﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;

namespace Hetymine.Executioner {
    /// <summary>
    /// Interaction logic for Display.xaml
    /// </summary>
    public partial class Display : Window {
        private DispatcherTimer _Timer;
        private static int _Count = 0;
        private static int _Index = -1;

        public Display() {
            InitializeComponent();            

            this.Time = 2100;
            this._Timer = new DispatcherTimer();
            this._Timer.Tick += new EventHandler(Timer_Tick);
          

            Styles.OuterBorder(this.cOuter);
            Styles.InnerBorder(this.cInner);
            Styles.TextBox(this.cDisplay);
            this.cDisplay.FontSize = this.cDisplay.FontSize + (this.cDisplay.FontSize * 0.15);
            this.UpdateLayout();
        }

        public string Text {
            get { return cDisplay.Text; }
            set { cDisplay.Text = value; }
        }
        public int Time { get; set; }

        public new void Show() {
            this._Timer.Interval = TimeSpan.FromMilliseconds(this.Time);
            this._Timer.IsEnabled = true;

            base.Show();

            int margin = Executioner.Config.GetInt("Appearance", "Margin", 10);

            if (Display._Count == 0) {
                Display._Index = -1;
            }

            ++Display._Count;
            ++Display._Index;

            margin += (int)(Display._Index * (margin + this.ActualHeight));

            Point p = Styles.Position(this.ActualWidth, this.ActualHeight, "centre top", margin);

            this.Left = p.X;
            this.Top = p.Y;

            this.Activate();
        }

        private void Timer_Tick(object sender, EventArgs e) {
            this._Timer.Stop();
            --Display._Count;
            this.Close();
        }
    }
}
